#include <bits/stdc++.h>
using namespace std;
int longsubstring(const string& str)
{
    int current_length = 0;
    int max_length = 0;
    vector<int> position(26,0);
    for(int i=0;i<str.length();++i)
    {
        int prevIndex = position[str[i]-'a'];
        int d = i-prevIndex;
        if(prevIndex<0||d>current_length)//如果距离d大于当前长度，后面元素添加进来不影响
            ++current_length;
        else{
            if(current_length>max_length)//当前不重复字符串长度是不是比之前记录的大，大就更新max_length
                max_length = current_length;
            current_length = i-prevIndex;//否则当前长度更新
        }
        position[str[i]-'a'] = i;//记录第i个字符最后出现的位置
    }
    if(current_length>max_length)
        max_length = current_length;
    return max_length;
}
int main() {
    string s = "arabcacfr";
    cout<<longsubstring(s)<<endl;
    return 0;
}